package diamondServer.businesslogic.manager;

import java.io.IOException;
import java.util.Set;

import org.apache.log4j.Logger;
import org.xml.sax.SAXException;

import diamondServer.businesslogic.configs.ResourceDataReader;
import diamondServer.businesslogic.resource.ResourceData;



public class ReaderRunner implements Runnable{
	
	private ResourceDataReader reader;
	private BusinessLogicManager manager;
	private static final Logger log = 
		Logger.getLogger(DefaultBLManager.class);	
	
	public ReaderRunner(ResourceDataReader reader, BusinessLogicManager blMgr) {
		this.reader = reader;
		this.manager = blMgr;
	}

	/**
	 * reads resources data and updates the manager
	 */
	@Override
	public void run() {
	 while(true){
		Set<ResourceData> resourcesD;
		try {
			resourcesD = reader.read();
		} catch (SAXException e) {
			log.error("xml file reading error",e);
			return;
		} catch (IOException e) {
			log.error("xml file reading error",e);
			return;
		}	
		
		manager.updateResources(resourcesD);
		
		try { Thread.sleep(5000); } catch (InterruptedException e) {}
	 }	
	}
	
}
